package com.example.blog_system.dao;

import com.example.blog_system.model.domain.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper {
    //分页展示某个文章评论
    @Select("SELECT * FROM t_comment WHERE article_id = #{aid} ORDER BY id DESC")
    List<Comment> selectCommentWithPage(Integer aid);

    //后台查询最新几条评论
    @Select("SELECT * FROM t_comment ORDER BY id DESC")
    List<Comment> selectNewComment();

    //发表评论
    @Insert("insert into t_comment (article id, created , author, ip, content )"+
            "values (#{articleId} ,#{created} , #{author}，#{ip} ,#{content})")
    void pushComment(Comment comment);

    //站点服务统计，统计评论数量
    @Select("SELECT COUNT(1) FROM t_comment")
    Integer countComment();


    //通过文章id删除评论信息
    @Delete("DELETE FROM t_comment WHERE article_id = #{aid}")
    void deleteCommentWithId(Integer id);

}
